<a href="reset.php" target="_new">RESET</a><br>
<a href="assign.php" target="_new">Assign</a><br>
<?php
include_once "methods.php";


//select days
$sql  = "select distinct day(from_unixtime(`start`)) as day, ";
$sql .= "month(from_unixtime(`start`)) as month, ";
$sql .= "year(from_unixtime(`start`)) as year ";
$sql .= " from sked ";
$sql .= "order by start asc";
$days = lom::getit($sql);
print "<h1>DAYS</h1>";
simple_table($days);



foreach ($days as $d){

	print "<h1>{$d['year']}-{$d['month']}-{$d['day']}</h1>\n";
	$start = "{$d['year']}-{$d['month']}-{$d['day']}";
	$tomorrow = $d['day'] + 1;
	$end = "{$d['year']}-{$d['month']}-$tomorrow";


print "<table><tr><td>";
print "<h2>Needs</h2>\n";

$sql  = "select auto, (stop - start)/3600 as Hours, from_unixtime(start) as `Start Time`, ";
$sql .= "from_unixtime(stop) as `Stop Time` from need ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";
$sql .= "order by start asc, stop asc";
$results = lom::getit($sql);
simple_table($results);
print "</td><td>";

print "<h2>Sked</h2>\n";

$sql  = "select employee as `Employee`, need, (stop - start)/3600 as Hours, ";
$sql .= "from_unixtime(start) as `Start Time`, ";
$sql .= "from_unixtime(stop) as `Stop Time`, auto ";
$sql .= "from sked ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";
$sql .= "order by start asc, stop asc";

$results = lom::getit($sql);


simple_table($results);
print "<br>";
print "<h2>Avail</h2>\n";

$sql  = "select auto, employee, (stop - start)/3600 as Hours, from_unixtime(start) as `Start Time`, ";
$sql .= "from_unixtime(stop) as `Stop Time` from avail ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";
$sql .= "order by start asc, stop asc";
$results = lom::getit($sql);
simple_table($results);


print "</td></tr>";




//
print "<tr><td>";
print "<h1>Stats</h1>\n";

$sql  = "select employee as Employee, count(auto) as `Shifts Assigned`, ";
$sql .= "sum((stop - start)/3600) as `Total Hours` ";
$sql .= "from sked ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";
$sql .= "group by employee order by sum((stop - start)/3600) asc";

$results = lom::getit($sql);
simple_table($results);

print "</td><td>";

$sql  = "select employee as Employee, count(auto) as `Avail Shifts`, ";
$sql .= "sum((stop - start)/3600) as `Available Hours` ";
$sql .= "from avail group by employee";

$results = lom::getit($sql);



print "<table><tr><td>";

$sql  = "select sum((stop - start)/3600) as `Scheduled Hours` ";
$sql .= "from sked ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";

$results = lom::getit($sql);
simple_table($results);

print "</td><td>";

$sql  = "select sum((stop - start)/3600) as `Needed Hours` ";
$sql .= "from need ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";

$results = lom::getit($sql);
simple_table($results);

print "</td><td>";

$sql  = "select sum((stop - start)/3600) as `Available Hours` ";
$sql .= "from avail ";
$sql .= "where start between UNIX_TIMESTAMP('$start') and UNIX_TIMESTAMP('$end') ";

$results = lom::getit($sql);
simple_table($results);
print "</td></tr></table>";

print "</td></tr></table>";

print "<hr>";

}
